package wsi.gui.function;

import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;

import javax.swing.JComponent;

import org.rygh.gui.swing.USwing;
import org.rygh.gui.swing.button.SButton;
import org.rygh.gui.swing.button.SCloseButton;
import org.rygh.gui.swing.component.SToolBar;
import org.rygh.gui.swing.presenter.SwingPresenter;
import org.rygh.gui.swing.table.STableView;
import org.rygh.gui.swing.view.one.SOneTableView;
import org.rygh.gui.swing.window.SwingWindow;

@SuppressWarnings("serial")
public class FunctionWindow extends SwingWindow implements
		FunctionPresenter.Display {

	private final SOneTableView view = new SOneTableView();
	private final SwingPresenter presenter;

	public FunctionWindow(SwingPresenter presenter) {
		super("Function Control Panel");

		this.presenter = presenter;

		layoutComponents();

		Rectangle rect = USwing.getScreenRect();
		setLocation((int) (rect.getWidth() - getWidth()), 0);
	}

	private JComponent createToolBar() {
		SToolBar bar = new SToolBar();

		bar.add(new SButton("Inputs", KeyEvent.VK_I, presenter, "viewInputs"));
		bar.add(new SButton("MD5", KeyEvent.VK_I, presenter, "viewInputsMD5"));
		bar.addSeparator();
		bar.add(new SButton("DataGuide", KeyEvent.VK_D, presenter,
				"viewDataGuide"));
		bar.addSeparator();
		bar.add(new SButton("Inject", KeyEvent.VK_I, presenter, "inject"));
		bar.addSeparator();
		bar.add(new SButton("Reset", KeyEvent.VK_T, presenter, "reset"));

		return bar;
	}

	@Override
	public STableView getTable() {
		return view.getTable();
	}

	private void layoutComponents() {
		view.setPreferredSize(new Dimension(580, 480));

		addCenterView(view);
		addTopView(createToolBar());

		addButton(new SCloseButton(presenter));
		addButton(new SButton("Run", KeyEvent.VK_N, presenter, "run"));
		addButton(new SButton("Resolve", KeyEvent.VK_R, presenter, "resolve"));
		addButton(new SButton("Isomorphic", KeyEvent.VK_H, presenter,
				"isomorphic"));
		addButton(new SButton("Yago", KeyEvent.VK_Y, presenter, "doYago"));
		addButton(new SButton("Inputs", KeyEvent.VK_I, presenter, "inputs"));

		pack();
	}

}
